package com.ruoyi.dataBase.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import cn.dev33.satoken.annotation.SaMode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.dataBase.domain.vo.IndustrialTransportPlanVo;
import com.ruoyi.dataBase.domain.bo.IndustrialTransportPlanBo;
import com.ruoyi.dataBase.service.IIndustrialTransportPlanService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 交通物流规划
 *
 * @author yangzhen
 * @date 2025-11-10
 */
@Tag(name = "交通物流规划", description = "交通物流规划相关接口")
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/dataBase/transportPlan")
public class IndustrialTransportPlanController extends BaseController {

    private final IIndustrialTransportPlanService iIndustrialTransportPlanService;

    /**
     * 查询交通物流规划列表
     */
    @Operation(summary = "查询交通物流规划列表", description = "用于查询交通物流规划列表")
    @SaCheckPermission("dataBase:transportPlan:list")
    @GetMapping("/list")
    public TableDataInfo<IndustrialTransportPlanVo> list(IndustrialTransportPlanBo bo, PageQuery pageQuery) {
        return iIndustrialTransportPlanService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出交通物流规划列表
     */
    @Operation(summary = "导出交通物流规划列表", description = "用于导出交通物流规划列表")
    @SaCheckPermission("dataBase:transportPlan:export")
    @Log(title = "交通物流规划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(IndustrialTransportPlanBo bo, HttpServletResponse response) {
        List<IndustrialTransportPlanVo> list = iIndustrialTransportPlanService.queryList(bo);
        ExcelUtil.exportExcel(list, "交通物流规划", IndustrialTransportPlanVo.class, response);
    }

    /**
     * 获取交通物流规划详细信息
     *
     * @param id 主键
     */
    @Operation(summary = "获取交通物流规划详细信息", description = "用于获取交通物流规划详细信息")
    @SaCheckPermission("dataBase:transportPlan:query")
    @GetMapping("/{id}")
    public R<IndustrialTransportPlanVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iIndustrialTransportPlanService.queryById(id));
    }

    /**
     * 新增交通物流规划
     */
    @Operation(summary = "新增交通物流规划", description = "用于新增交通物流规划")
    @SaCheckPermission("dataBase:transportPlan:add")
    @Log(title = "交通物流规划", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody IndustrialTransportPlanBo bo) {
        return toAjax(iIndustrialTransportPlanService.insertByBo(bo));
    }

    /**
     * 修改交通物流规划
     */
    @Operation(summary = "修改交通物流规划", description = "用于修改交通物流规划")
    @SaCheckPermission(value = {"dataBase:transportPlan:edit", "dataBase:transportPlan:review"}, mode = SaMode.OR)
    @Log(title = "交通物流规划", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody IndustrialTransportPlanBo bo) {
        return toAjax(iIndustrialTransportPlanService.updateByBo(bo));
    }

    /**
     * 删除交通物流规划
     *
     * @param ids 主键串
     */
    @Operation(summary = "删除交通物流规划", description = "用于删除交通物流规划")
    @SaCheckPermission("dataBase:transportPlan:remove")
    @Log(title = "交通物流规划", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iIndustrialTransportPlanService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
